package cn.melonlib.security.encryption.comp.enc.config;

import cn.melonlib.security.encryption.anno.SecurityService;
import cn.melonlib.security.encryption.comp.enc.interceptor.SecurityInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.support.ApplicationObjectSupport;

import javax.annotation.Resource;

@Configuration
@DependsOn({"securityInterceptor"
})
public class SecurityInterceptorAnnotationConfig extends ApplicationObjectSupport {

    @Resource
    private SecurityInterceptor securityInterceptor;

    @Bean
    public DefaultPointcutAdvisor encdec(){
        AnnotationMatchingPointcut pointcut=new AnnotationMatchingPointcut(SecurityService.class,true);
        DefaultPointcutAdvisor defaultPointcutAdvisor=new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(pointcut);
        defaultPointcutAdvisor.setAdvice(securityInterceptor);
        defaultPointcutAdvisor.setOrder(100);
        return defaultPointcutAdvisor;
    }
}
